package pl.edu.agh.sius.gui.model;

import java.util.ArrayList;
import java.util.List;

import javax.swing.table.AbstractTableModel;

public abstract class TableModel extends AbstractTableModel {
	private static final long serialVersionUID = -4636324596793861691L;

	protected List<String> columns = new ArrayList<String>();
	protected ArrayList<Object> dataList = new ArrayList<Object>();
	
	public TableModel(List<Object> data) {
		super();
		setData(data);
	}
	
	public void setData(List<Object> data) {
		dataList.clear();
		dataList.addAll(data);
		fireTableDataChanged();
	}
	
	public Object getData(int index) {
		if(index < 0)
			return null;
		return dataList.get(index);
	}
	
	public List<Object> getAllData() {
		return dataList;
	}
	
	public int getColumnCount() {
		return columns.size();
	}

	public int getRowCount() {
		return dataList.size();
	}

	public String getColumnName(int col) {
		return columns.get(col);
	}
}
